<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
    <%@taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<jsp:include page="/common/commonCss.jsp" />
<jsp:include page="/common/commonJs.jsp" />
<title>嘉童游乐中心-审核库存调整</title>
<script type="text/javascript">
	$(document).ready(function(){
		 //获得上次保存的调整商品
		getSavedBeans();
		 
		//递交
		$("#btnComplete").click(function() 
		{
			$.messager.confirm('提示', '确认要提交吗?', function(r) {
				if (r) {
					$("#handleResult").val("1"); 
					$("#form2").submit();
				}
			});
		
		});

		//退单
		$("#btnBack").click(function() 
		{ 
			$.messager.confirm('提示', '确认要退回吗?', function(r) {
				if (r) {
			$("#handleResult").val("2"); 
			$("#form2").submit();
				}
			});
		});
		
		$("#endProcess").click(function() {
			$.messager.confirm('提示', '确认要关闭流程吗?', function(r) {
				if (r) {
					$("#handleResult").val("4"); //结束流程
					$("#form2").submit();
				}
			});
		});
		
	}); 

	function getSavedBeans()
	{
		 $.ajax({
				url:"${basePath}StockCorrect/getSavedCorrectPrds.shtml",
				data:{"fkStgadjId":"${scmStgAdj['pkStgadjId']}","fkBranId":"${scmStgAdj['fkBranId']}"},
				dataType:"json",
				type:"post",
				async:false,
				success:function(result)
				{
					initCorrectTable(result);
				},
				error : function(XMLHttpRequest) {
					ajaxError(XMLHttpRequest);
				}
			});
	}

	function initCorrectTable(data) {
		if(data == null)
			{
			return;
			}
		trimJsonArray(data); 
		html = "";
		$.each(data, function(ind, obj)
		{
			var num = (obj.stgCnt == "" ? 0 : obj.stgCnt);
			html += "<tr><td>" + (parseInt(1) + ind) + "</td>";
			html += "<td>" + obj.pkPrdId + "</td>";
			html += "<td>" + obj.prdName + "</td>";
			html += "<td>" + obj.cateName + "</td>";
			html += "<td>" + obj.prdSpec + "</td>";
			html += "<td>" + obj.unitName + "</td>";
			html += "<td>" + obj.stkCnt + "</td>";
			html += "<td>" + num + "</td>";
			html += "<td>"+obj.adjCnt+"</td>";
			html += "<td>"+obj.comments+"</td></tr>";
			});
		$("#tbody").html(html);
	
	}
</script>
</head>
<body class="bg">
<div class="content m_auto">
	<div class="content_l mt10">
    	<ul>
        	<shiro:hasPermission name="StockGoodsIn/toStock_goodsIn.shtml">
					<li><a href="${basePath}StockGoodsIn/toStock_goodsIn.shtml"><i class="nav_icon_b"></i><br>商品入库</a></li>
				</shiro:hasPermission>
				<shiro:hasPermission name="StockQuery/toStockQuery.shtml">
					<li><a href="${basePath}StockQuery/toStockQuery.shtml"><i class="nav_icon_b"></i><br>库存查询</a></li>
				</shiro:hasPermission>
				<shiro:hasPermission name="StockGoodsOut/toStockGoodsOut.shtml">
					<li><a href="${basePath}StockGoodsOut/toStockGoodsOut.shtml"><i class="nav_icon_b"></i><br>商品出库</a></li>
				</shiro:hasPermission>
				<shiro:hasPermission name="StockTaking/toStockTaking.shtml">
					<li><a href="${basePath}StockTaking/toStockTaking.shtml"><i class="nav_icon_a"></i><br>库存盘点</a></li>
				</shiro:hasPermission>
				<shiro:hasPermission name="StockCorrect/toStockCorrect.shtml">
					<li class="content_hover"><a href="${basePath}StockCorrect/toStockCorrect.shtml"><i class="nav_icon_f"></i><br>库存调整</a></li>
				</shiro:hasPermission>
			</ul>
    </div>
    <div class="content_r mt10">
    	<div class="p20">
    	<div class="file_single_dl f14 fixed">
       		 <dl class="fixed"  >
                <dd ><label> 库存调整申请编号：</label>${scmStgAdj['pkStgadjId']}</dd>
                <dd><label>创建人：</label>${scmStgAdj['usrName']}</dd>
                <dd><label>创建时间：</label>${applyTime}</dd>
           		 </dl>
        	 </div>
		         <div id="scrollTable" style="width:1120px; height: 232px;">
		            <table class="table">
		          	    <col width="80px"></col>
		                <col width="130px"></col>
		                <col width="90px"></col>
		                <col width="90px"></col>
		                <col width="80px"></col>
		                <col width="80px"></col>
		                <col width="130px"></col>
		                <col width="130px"></col>
		                <col width="120px"></col>
		                <col></col>
		                <tbody>
		                 	<tr>
		                    	<th>序号</th>
		                        <th>商品编号</th>
		                        <th>商品名称</th>
		                        <th>商品分类</th>
		                        <th>规格</th>
		                        <th>单位</th>
		                        <th>盘点实际数量</th> 
		                        <th>商品实际库存数量</th> 
		                        <th>调整数量</th> 
		                        <th>调整原因</th> 
		                     </tr>
		                     </tbody>
		                  </table>
		              <div>
		            <table class="table" id="selectProduct" >
						<col width="80px"></col>
		                <col width="130px"></col>
		                <col width="90px"></col>
		                <col width="90px"></col>
		                <col width="80px"></col>
		                <col width="80px"></col>
		                <col width="130px"></col>
		                <col width="130px"></col>
		                <col width="120px"></col>
		                <col></col>
		                <tbody id="tbody">
		                  
		                </tbody>
		            </table>
		            </div>
		        </div>
                   <dl class="fixed order_dl">
                      <dd><label><b>当前状态：</b></label>
                       	 ${scmStgAdj.workflowVo.statusDesc}
                     </dd>
                 	<dd><label><b>处理历史：</b></label>
                     <dd>
                         <table class="table">
                             <tr>
                                 <th>时间</th>
                                 <th>处理人</th>
                                 <th>结果</th>
                                 <th>处理意见</th>
                             </tr>
                             <c:forEach items="${scmStgAdj.workflowVo.optHisVoList }" var="his">
								<tr>
								<td style="width: 40%">${his.optTime }</td>
								<td>${his.optName }</td>
								<td>${his.result }</td>
								<td title="${his.advice}">
								<c:if test="${his.advice != null}">
									<c:choose>
										<c:when test="${his.advice.length() > 5}">
											${his.advice.substring(0,5)}...
										</c:when>
										<c:otherwise>
											${his.advice}
										</c:otherwise>
									</c:choose>
								</c:if>
								</td>
							</tr>
							</c:forEach>
                         </table>
                     </dd>
        			<c:if test="${scmStgAdj.status == '2' && scmStgAdj.workflowVo.isStartUser != '1' && scmStgAdj.workflowVo.isCurrtOpt == '1'}">
						<form action="${basePath }StockCorrect/completeStockCorrect.shtml" method="post" id="form2" name="form2">
									<input type="hidden" name="fkStgadjId" value="${scmStgAdj['pkStgadjId']}" />
									<input type="hidden" name="handleResult" id="handleResult" />
									<input type="hidden" name="fkBranId" value="${scmStgAdj['fkBranId']}" />
									<input type="hidden" name="modiBy" value="${scmStgAdj['applyBy']}" />
									<input type="hidden" name="businessKey" value="${scmStgAdj.pkStgadjId }" />
									<input type="hidden" name="processInstanceId" value="${scmStgAdj.fkFlowinstId }"/> 
								<dd><label>审批结果：</label> 
									<input type="radio" name="handleAdvice" value="1" checked style="width: 20px" />同意 
									<input type="radio" name="handleAdvice" value="0" style="width: 20px" />不同意
								</dd>
								<dd>
									<label style="width:200px" class="vt">审批意见：</label>
                            		<textarea class="w200 textare" name="handleReason" ></textarea>
								</dd>
						</form>
					</c:if>
            </dl>
                    <div class="btm_btn mt10">
                          <dl>
							<c:choose>
							<c:when test="${scmStgAdj.status == '2' &&  scmStgAdj.workflowVo.isCurrtOpt == '1'}">
								<c:choose>
								<c:when test="${scmStgAdj.workflowVo.isStartUser == '1' && scmStgAdj.workflowVo.isCurrtOpt == '1'}">
									<dd><input type="button" class="btn" onClick="javascript:history.go(-1);" value="返回" /></dd>
                        			<dd><input type="button" class="btn" id="reApply" value="重新申请" /></dd>
								</c:when>
								<c:otherwise>
									<dd><input type="button" class="btn" id="btnComplete" value="提交" /></dd>
									<dd><input type="button" class="btn" id="btnBack" value="退单" /></dd>
								</c:otherwise>
								</c:choose>
								<dd><input type="button" class="btn" id="endProcess" value="关闭" /></dd>
								<dd><input type="button" class="btn" onClick="javascript:history.go(-1);" value="返回" /></dd>
							</c:when>
							<c:otherwise>
								<c:choose>
								<c:when test="${scmStgAdj.status == '1'}">
									  	<dd><input type="button" class="btn" onClick="javascript:history.go(-1);" value="返回" /></dd>
                     		 			<dd><input type="button" class="btn" id="btnSave" value="保存" /></dd>
                      					<dd><input type="button" class="btn" id="btnSubmit" value="提交" /></dd>
								</c:when>
								<c:otherwise>
									<input type="button" class="btn" onClick="javascript:history.go(-1);" value="返回" />
								</c:otherwise>
								</c:choose>
							</c:otherwise>
						</c:choose>
						</dl>
                    </div>
                    </div>
        </div>
      
        </div>
</body>
</html>